$(document).ready(function () {
    var praseFrom=new xhForm($('#xh_form'));
    praseFrom.parse();


    $('#save').click(function () {
        $.ajax({
            url:baseUrl+'Tch/saveTemplate',
            data:$('#xh_form').serialize(),
            dataType:'json',
            method:'post',
            success:function (data) {
                console.log(data);
            },
            error:function (data) {
                console.log(data);
            },
            complete:function () {
                location.reload();
            }
        })
    });
    $('#table').on('click','.del',function () {
        var iTPId = $(this).attr('tpId');
        $.ajax({
            url:baseUrl+'Tch/delTp/'+iTPId,
            method:'post',
            success:function (data) {
                window.top.swal('','成功','success');
            },
            error:function (data) {
                console.log(data);
                window.top.swal('','失败','error');
            },
            complete:function () {
                location.reload();
            }
        })
    });

    $('#table').on('click','.edit',function () {
        var iTPId = $(this).attr('tpId');
        $.ajax({
            url:baseUrl+'Tch/getTp/'+iTPId,
            dataType:'json',
            method:'post',
            success:function (data) {
                console.log(data);
                praseFrom.fill(data);
            },
            error:function (data) {
                console.log(data);
                window.top.swal('','失败','error');
            },
        })
    });

    $('#reset').click(function () {
        praseFrom.reset();
        $('[name=iTPType]').val(1);
    });
});